tl;dr, a safe way to program, for script, by adding these lines of code at the top of bash scripts for reliability.

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

set

A builtin that changes shell options. See manual.

IFS

The Internal Field Separator controls word splitting (or tokenization).

IFS='\n' # parse each line instead of each word
for name in ${names[@]}; do
echo $name
done

Wayne Gretzky

Back to Languages/Bash

David Beckham

```

source